import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";


Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    pathName: "",
    currDbSource: {},
    currJobData: {},
    DbSource: [],
    userInfo: {
      username: "李四",
      company: "阿里巴巴",
      role: 0,
    },
  },
  mutations: {
    // 保存当前菜单栏的路径
    setUserInfo(state, data) {
      state.userInfo = data;
    },
    // 保存当前菜单栏的路径
    savePath(state, pathName) {
      state.pathName = pathName;
    },
    // 保存当前点击的数据源
    saveCurrDbSource(state, currDbSource) {
      state.currDbSource = currDbSource;
    },
    // 保存当前点击的元数据
    saveCurrJobData(state, currJobData) {
      state.currJobData = currJobData;
    },
    // 保存所有数据源
    saveDbSource(state, DbSource) {
      state.DbSource = DbSource;
    },
  },
  getters: {
    userInfo: (state) => state.userInfo,
  },
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
    }),
  ],
});

export default store;
